// JavaScript Document
var timer = null;
var offset = 3000;
var index = 3;
var left = 0;
var target = ["01","02","03","04","05"];

//大图交替轮换
function slideImage(i){
    var id = 'pic_'+ target[i];
    $('#'+ id)
        .animate({opacity: 1}, 800, function(){
        }).show()
        .siblings(':visible')
		.animate({opacity: 1}, 800).hide();
}
//bind smallpic a
function hookThumb(){    
    $('#num li a')
        .bind('mousemove', function(){
            if (timer) {
                clearTimeout(timer);
            }                
            var id = this.id;            
            index = getIndex(id.substr(4));
            rechange(index);
            slideImage(index); 
            timer = window.setTimeout(auto, offset);  
            this.blur();            
            return false;
        });
}

//get index
function getIndex(v){
    for(var i=0; i < target.length; i++){
        if (target[i] == v) return i;
    }
}

function rechange(loop){
    var nid = 'num_'+target[loop];
	var cid = 'cnt_'+target[loop];
	$('#num li a').removeClass('anniu_cur');
	$('#'+nid).addClass('anniu_cur');
	$('#cnt li').addClass('hidden');
	$('#'+cid).removeClass();
}

function auto(){
    index++;
    if (index > 4){
        index = 0;
    }
    rechange(index);
    slideImage(index);
    timer = window.setTimeout(auto, offset);
}

function showCnt() {
	$('#trees div').each(function(){
		$(this).bind('mouseover', function(){
				$(this).children('span').children('h3').addClass('hover');
				$(this).children('.i-mc').css('display', 'block');
			});
		$(this).bind('mouseout', function(){
				$(this).children('span').children('h3').removeClass('hover');
				$(this).children('.i-mc').css('display', 'none');
			});
	});
}


function hookBtn() {
	$('.flash02 div').filter('#prev,#next')
		.bind('click', function(){
			var id = this.id;
			var total = $("#roll li").length;
			var maxv = total-4;
			var per = 112;
			var minv = -(maxv*per);
			if (id == 'prev') {
				if (left < 0)
				{
					left += per;
					var mleft = left+"px";
					$("#roll").css('margin-left', mleft);
				}
			}else{
				if (left > minv)
				{
					left -= per;
					var mleft = left+"px";
					$("#roll").css('margin-left', mleft);
				}
			}
		}); 
}

function bianse() {
	$("tr:even").addClass("s_oushuhang");
	$("tr:odd").addClass("s_jishuhang");
	$('table tr').each(function() {
		$(this).bind('mouseover', function() {
			$(this).addClass('s_mouseover');
		});
		$(this).bind('mouseout', function() {
			$(this).removeClass('s_mouseover');
		});
	});
}

$(function(){ 
    auto();  
    hookThumb(); 
    hookBtn();
	showCnt();
	bianse();
});
